package cn.easier.activity.console.service.impl;

import cn.easier.activity.console.repository.ActivityPrizeRepository;
import cn.easier.activity.console.service.ActivityPrizeService;
import cn.easier.activity.web.entity.ActivityPrize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 活动奖品ServiceImpl
 */
@Service
@Transactional
public class ActivityPrizeServiceImpl implements ActivityPrizeService {

    @Autowired
    ActivityPrizeRepository activityPrizeRepository;

    @Override
    public ActivityPrize findOne(Integer id, Integer activityInfoId) {
        return activityPrizeRepository.findActivityPrizeByIdAndActivityInfoId(id, activityInfoId);
    }

    @Override
    public List<ActivityPrize> findByActivityInfoId(Integer activityInfoId) {
        return activityPrizeRepository.findActivityPrizesByActivityInfoIdAndStatus(activityInfoId,0);
    }

    @Override
    public ActivityPrize saveAndFlush(ActivityPrize activityPrize) {
        return activityPrizeRepository.saveAndFlush(activityPrize);
    }

    @Override
    public Boolean delete(Integer id, Integer activityInfoId) {
        //todo 删除对应的文件（图片文件）
        return activityPrizeRepository.deleteFlag(id, activityInfoId) > 0 ? true : false;
    }
}
